package com.yisu.auction.ewf.web.springmvc;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;

import java.io.IOException;
import java.io.OutputStream;

/**
 * 返回json时使用, 支持json , jsonp, 需配合RequestContext 使用, 注意
 *
 * Created by LKL on 5/8/15.
 */
public class JsonMessageConverter extends FastJsonHttpMessageConverter {

    @Override
    protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException,
                                                                                     HttpMessageNotWritableException {
        OutputStream out = outputMessage.getBody();
        byte[] bytes = JsonCommonRender.getJsonResult(obj).getBytes(getCharset());
        out.write(bytes);
    }
}
